﻿<div id="tb">
    <table cellpadding="0" cellspacing="0" style="width: 100%">
        <tr>
            <td>
                <a href="#" class="easyui-linkbutton" onclick="javascript: $('#DataSourceSetting').datagrid('mfInsertRow')" iconcls="iconfont iconfont-jia1" plain="true">增加</a>
                <a href="#" class="easyui-linkbutton" onclick="javascript: $('#DataSourceSetting').datagrid('mfMoveUp')" iconcls="iconfont iconfont-xiangshang" plain="true">上移</a>
                <a href="#" class="easyui-linkbutton" onclick="javascript: $('#DataSourceSetting').datagrid('mfMoveDown')" iconcls="iconfont iconfont-paixu" plain="true">下移</a>
                <a href="#" class="easyui-linkbutton" onclick="javascript: $('#DataSourceSetting').datagrid('mfDeleteRow')" iconcls="iconfont iconfont-shanchu" plain="true">删除</a>
                <a href="#" class="easyui-linkbutton" onclick="save()" iconcls="iconfont iconfont-baocun" plain="true">保存</a>
            </td>
        </tr>
    </table>
</div>
<table id="DataSourceSetting" rownumbers="false" fit="true" pagination="false" fitcolumns="true" striped="true" border="false" idfield="Id"
       autorowheight="false" toolbar="#tb" singleselect="false">
    <thead>
        <tr>
            <th data-options="field:'ck',checkbox:true"></th>
            <th field="Name" width="80" halign='center' editor="{type:'validatebox'}">
                名称
            </th>
            <th field="DBName" width="80" halign='center'
                editor="{type:'combobox',options:{data:DBNames,required:false,panelHeight:'auto'}}">
                数据库
            </th>
            <th field="SQL" width="400" halign='center' editor="{type:'textarea'}">
                SQL
            </th>
        </tr>
    </thead>
</table>

<script>
    var id = queryString('id');
    var DBNames = @Html.Raw(ViewBag.DBNames);
    $('#DataSourceSetting').datagrid().datagrid('enableCellEditing');
</script>
<script>
    function pageLoad() {
        //编辑
        if (id) {
            $("#Id").val(id);
            addAjaxParam("formId", id);
            commitAjax("GetDataSourceSetting", {
                CallBack: function (data) {
                    if (data) {                         
                        $('#DataSourceSetting').datagrid('loadData', data);
                    }
                }
            });
        }
    }

    function save()
    {
        var rows = $('#DataSourceSetting').datagrid('getRows');
        addAjaxParam('formId', id);
        addAjaxParam('data', JSON.stringify(rows));
        commitAjax('SaveDataSourceSetting', {
            CallBack: function (data) {
                closeWindow();
            }
        });
    }
</script>
